package com.googlecode.garbagecan.dbtest.mysql;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TestMySQL {
	public static void main(String[] args) throws Exception {
		Connection conn = getConnection();
		String value = "Don\\'t!";
		String sql = "SELECT QUOTE('"+value+"')";
		QueryRunner queryRunner = new QueryRunner();
		value = queryRunner.query(conn, sql, new ResultSetHandler<String>() {
			public String handle(ResultSet rs) throws SQLException {
				if (!rs.next()) {
					return null;
				}
				String value = rs.getString(1);
				return value;
			}
		});
		System.out.println(value);
	}
	
	public static Connection getConnection() throws Exception {
		Class.forName("org.gjt.mm.mysql.Driver");
		String url = "jdbc:mysql://172.17.23.121:3306/fkong";
		Connection conn = DriverManager.getConnection(url, "fkong", "fkong");
		conn.setAutoCommit(false);
		return conn;
	}
}
